﻿using System.ComponentModel;
using System.IO;
using ChiWalker.Utilities;
using Styx;
using Styx.Helpers;

namespace ChiWalker.Settings
{
    internal class ChiWalkerSettings : Styx.Helpers.Settings
    {
        private static ChiWalkerSettings _instance;

        public ChiWalkerSettings()
            : base(Path.Combine(CharacterSettingsPath, "ChiWalkerSettings.xml"))
        {
        }

        public static string CharacterSettingsPath
        {
            get
            {
                string settingsDirectory = Path.Combine(Styx.Common.Utilities.AssemblyDirectory, "Settings");
                return Path.Combine(Path.Combine(settingsDirectory, "ChiWalker", StyxWoW.Me.RealmName), StyxWoW.Me.Name);
            }
        }

        public static ChiWalkerSettings Instance
        {
            get { return _instance ?? (_instance = new ChiWalkerSettings()); }
        }

        [Setting]
        [Category("Group")]
        [Styx.Helpers.DefaultValue(true)]
        public bool BuffGroup { get; set; }

        [Setting]
        [Styx.Helpers.DefaultValue(false)]
        [Category("Movement")]
        public bool DisableMovement { get; set; }

        [Setting]
        [Styx.Helpers.DefaultValue(60)]
        [Limit(0, 100)]
        [Category("Rest")]
        public int EatingPct { get; set; }

        [Setting]
        [Styx.Helpers.DefaultValue(60)]
        [Limit(0, 100)]
        [Category("Rest")]
        public int DrinkingPct { get; set; }

        [Setting]
        [Styx.Helpers.DefaultValue(SpellUsage.OnCoolDown)]
        [Category("Trinket")]
        public SpellUsage Trinket1 { get; set; }

        [Setting]
        [Styx.Helpers.DefaultValue(SpellUsage.OnCoolDown)]
        [Category("Trinket")]
        public SpellUsage Trinket2 { get; set; }

        #region Late Loading

        private DruidSettings _druid;
        private WarlockSettings _lock;
        private MageSettings _mage;
        private MonkSettings _monk;
        private RogueSettings _rogue;
        private WarriorSettings _warrioir;


        [Browsable(false)]
        public MageSettings Mage
        {
            get { return _mage ?? (_mage = new MageSettings()); }
        }

        [Browsable(false)]
        public MonkSettings Monk
        {
            get { return _monk ?? (_monk = new MonkSettings()); }
        }

        [Browsable(false)]
        public RogueSettings Rogue
        {
            get { return _rogue ?? (_rogue = new RogueSettings()); }
        }

        [Browsable(false)]
        public WarlockSettings Warlock
        {
            get { return _lock ?? (_lock = new WarlockSettings()); }
        }

        [Browsable(false)]
        public DruidSettings Druid
        {
            get { return _druid ?? (_druid = new DruidSettings()); }
        }

        [Browsable(false)]
        public WarriorSettings Warrior
        {
            get { return _warrioir ?? (_warrioir = new WarriorSettings()); }
        }

        #endregion

        public static void SaveAll()
        {
            Instance.Save();
            Instance.Druid.Save();
            Instance.Mage.Save();
            Instance.Monk.Save();
            Instance.Rogue.Save();
            Instance.Warlock.Save();
            Instance.Warrior.Save();
        }
    }
}